package service;

import enumUtil.TimeEnum;
import interfave.ConvertInterface;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * @Classname TimeConvert
 * @Description 时间转化类
 * @Date 2021/12/1 16:44
 * @Created by silence(dxs)
 */
public class TimeConvert {

    public Long convertToStamp(ConvertInterface<Date,Long> convertInterface, Date date, TimeEnum timeEnum){
        Objects.requireNonNull(convertInterface);
        Objects.requireNonNull(date);
        Objects.requireNonNull(timeEnum);
        Long convert = convertInterface.convert(date);
        if(timeEnum==TimeEnum.SECOND){
            String s = String.valueOf(convert);
            return  Long.valueOf(s.substring(0, s.length()-4));
        }else{
            return convert;
        }

    }
}
